<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p {
            height: 50px;
            width: 50px;
            border: 1px solid black;
            text-align: center;
            line-height: 50px;
        }
    </style>
</head>

<body>
    <div class="app">
        <p>{{num}}</p>
        <button @click="stop">停止计数</button>
        <button @click="action">开始计数</button>
    </div>
</body>
<script src="../vue.js"></script>
<script>
    let a;
    let app = new Vue({
        el: ".app",
        data: {
            num: 0,
        },
        methods: {
            stop: function() {
                clearInterval(a)
            },
            action: function() {
                console.log(1);
                a = setInterval(function() {
                    app.num++
                        // console.log(2);
                }, 100)
            }

        }
    })
</script>

</html>